<?php
/**
 * Created by PhpStorm.
 * User: xiaomage
 * Date: 2020/12/11
 * Time: 13:22
 */

namespace common\data;


use common\logic\Logic;

class DataView
{
    /**
     * 使用的模型
     * @var null
     */
    private $logic = null;

    /**
     * 允许更新的数据字段
     * @var array
     */
    private $put = [];

    /**
     * 查询的query参数
     * @var array
     */
    private $query = [];

    /**
     * 暴露给前端的字段
     * @var array
     */
    private $fields = [];

    /**
     * DataView constructor.
     * @param string $logic 使用的业务类
     * @param array $query 查询的参数
     * @param array $fields 暴露的字段
     * @param array $put 允许更新的字段
     */
    public function __construct($logic = null, $query = [], $fields = [], $put = [])
    {
        $this->setLogic($logic);
        $this->setPut($put);
        $this->setQuery($query);
        $this->setFields($fields);
    }

    /**
     * @return null
     */
    public function getLogic()
    {
        return $this->logic;
    }

    /**
     * @param $logic
     * @return $this
     */
    public function setLogic($logic)
    {
        $this->logic = $logic;

        return $this;
    }

    /**
     * @return array
     */
    public function getPut(): array
    {
        return $this->put;
    }

    /**
     * @param array|string $put
     * @return $this
     */
    public function setPut($put = [])
    {
        if ($put) {
            $this->put = is_array($put) ? $put : [$put];
        }
        return $this;
    }

    /**
     * @return array
     */
    public function getQuery(): array
    {
        return $this->query;
    }

    /**
     * @param array $query
     * @return $this
     */
    public function setQuery(array $query = [])
    {
        if ($query) {
            $this->query = is_array($query) ? $query : [$query];
        }

        return $this;
    }

    /**
     * @return array
     */
    public function getFields(): array
    {
        return $this->fields;
    }

    /**
     * @param array $query
     * @return $this
     */
    public function setFields(array $query = [])
    {
        if ($query) {
            $this->query = is_array($query) ? $query : [$query];
        }

        return $this;
    }
}